package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.DateUtil;
import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class DailyCommend extends BaseDomain {

    public static final int TYPE_NORMAL = 0;//正常的推荐
    public static final int TYPE_HOT = 1;//头条推荐
    public static final int TYPE_DAILYCOMEND = 4;

    @JsonFormat(pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date schedule;//推荐日报的日期

    private String coverUrl;//封面

    private String source;//来源(某个机构或做作者笔名)

    private String title;//标题

    private String subTitle;//副标题

    private Integer type = TYPE_NORMAL;//状态,默认是正常推荐状态

    private Integer sequence;//日报消息的优先级

    private DailyCommendContent commendContent;

    public String getJsonString() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", getId());
        if (schedule != null) {
            map.put("schedule", DateUtil.date2string(schedule, "yyyy-MM-dd"));
        }
        map.put("title", title);
        map.put("subTitle", subTitle);
        map.put("type", type);
        map.put("source", source);
        map.put("coverUrl", coverUrl);
        map.put("sequence", sequence);
        return JSONUtil.toJSONString(map);
    }

    public String getTypeDisplay() {
        if (type == TYPE_NORMAL) {
            return "正常推荐";
        } else if (type == TYPE_HOT) {
            return "热门推荐";
        }
        return "";
    }
}